package imse.team0.processors;

import imse.team0.orderws.InvalidRequest;
import imse.team0.orderws.data.InvalidationReasonType;
import imse.team0.orderws.data.OrderType;
import imse.team0.orderws.data.ReceiptAcknowledgmentType;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.cxf.message.MessageContentsList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.BASE64Encoder;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author Eugen, 4/26/12 5:26 PM
 */
public class BuildOrderReplies {

    private static Map<String, Message> orderRequestStore = new HashMap<String, Message>(1);
    /**
     * Using requestCounter to set unique ids to messages so as to correlate them
     * through the whole processing path (used to detemine the processing time of
     * a single message in remote logging)
     */
    private static AtomicLong requestCounter = new AtomicLong(0);

    private static final String NL = System.getProperty("line.separator");
    private static final AtomicLong uniqueID = new AtomicLong(0);
    private static final Logger RESULT_LOGGER = LoggerFactory.getLogger("imse.team0.results");

    public void buildAcknowledgeMessage(Exchange exchange) {
        OrderType order = (OrderType) exchange.getIn().getBody(List.class).get(0);
        ReceiptAcknowledgmentType okReply = new ReceiptAcknowledgmentType();
        okReply.setCode(200);
        okReply.setText("Order with correlation: ClientID=" + order.getClientID() + ";TimeStamp=" + order.getTimestamp() + "; received.");
        //System.out.println(okReply.getText());
        okReply.setReceiptTime(new Date().getTime());
        //exchange.getIn().setBody(okReply);
        exchange.getOut().setBody(okReply);

    }
}
